package com.probiz.estore.common.model.product;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.common.model.product.base.ProductMediaTbl;

/**
 * Model class for ProductMedia. Add not database mapped fileds in this class.
 * 商品媒体
 */
public class ProductMedia extends ProductMediaTbl {
	public static final Integer DEFAULT_SORTORDER = Integer.valueOf(1000);
	public static final Short TYPE_IMAGE = Short.valueOf((short) 0);
	public static final Short TYPE_ACCESSORY = Short.valueOf((short)1);
  	/**
	 * Default Empty Constructor for class ProductMedia
	 */
	public ProductMedia () {
		super();
	}
	
	/**
	 * 定义实体的业务名取值； productMediaName
	 * 必须手工完成这个部分，否则编译不通过。
	 */
	public String getProductMediaName () {
		if (productMediaId == null)
	        return "";
	    else
			//返回一个指定有业务意义的属性值;
			//如：product的VO就用product.productName
	        return this.mediaDescription;
	}
	
	/**
	 * Default Key Fields Constructor for class ProductMedia
	 */
	public ProductMedia (
		 Integer in_productMediaId
		) {
		super (
		  in_productMediaId
		);
	}
	
	/**
	 * 媒体标题带后缀
	 * @return
	 */
	public String getMediaTitle(){
		if(StringUtils.isNotBlank(mediaDescription)){
			return mediaDescription;
		}else if(StringUtils.isNotBlank(mediaUrl)){
			String[] urls = mediaUrl.split("/");
			return urls[urls.length-1];
		}else{
			return null;
		}
	}
	/**
	 * 媒体标题带后缀
	 * @return
	 */
	public String getMediaTitleWithMimeType(){
		if(StringUtils.isNotBlank(mediaDescription)){
			if(StringUtils.isNotBlank(mediaUrl) && mediaUrl.lastIndexOf(".")!=-1){
				String suffix = mediaUrl.substring(mediaUrl.lastIndexOf("."));
				return mediaDescription+suffix;
			}else{
				return mediaDescription;
			}
		}else if(StringUtils.isNotBlank(mediaUrl)){
			String[] urls = mediaUrl.split("/");
			return urls[urls.length-1];
		}else{
			return null;
		}
	}
}
